package com.dzu.easy;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoDong
 * @date 2022/10/19 9:45
 * @description 506. 相对名次
 */
public class Test506 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(findRelativeRanks(new int[]{10, 3, 8, 9, 4})));

    }

    public static String[] findRelativeRanks(int[] score) {
        String[] ss = new String[]{"Gold Medal", "Silver Medal", "Bronze Medal"};

        int n = score.length;

        String[] ans = new String[n];

        int[] clone = score.clone();
        Arrays.sort(clone);
        Map<Integer, Integer> map = new HashMap<>();

        for (int i = n - 1; i >= 0; i--) {
            map.put(clone[i], n - 1 - i);
        }
        for (int i = 0; i < n; i++) {
            int rank = map.get(score[i]);
            ans[i] = rank < 3 ? ss[rank] : String.valueOf(rank + 1);
        }
        return ans;

    }
}
